<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lysee 参考手册 - 3.2.类型</title>
<meta name="author" content="libudi@hotmail.com">
<meta name="copyright" content="copyright 2003-2010 LiBUDI(libudi@hotmail.com)">
<link href="index.css" rel="stylesheet" type="text/css">
<link href="logo.ico" rel="Shortcut Icon">
</head>
<body> 
<table width="760" border="0" align="center" cellpadding="0" cellspacing="8"> 
  <tr> 
    <td align="left" valign="middle"> <table width="100%"  border="0" cellspacing="0" cellpadding="0"> 
        <tr>
          <td align="left" valign="top"><a href="index.html"><img src="logo.png" width="327" height="70" border="0"></a></td> 
          <td align="right" valign="bottom"> <a href="301.html">&lt;PREV</a>&nbsp;&nbsp;<a href="index.html">HOME</a>&nbsp;&nbsp;<a href="303.html">NEXT&gt;</a></td> 
        </tr> 
      </table></td> 
  </tr> 
  <tr> 
    <td class="footer_line"><a href="300.html">3.语言参考</a> - <strong>2.类型</strong><br> 
      <br> 
      Lysee 中的对象都有其明确的类型。</td> 
  </tr> 
  <tr> 
    <td><a name="basis" id="basis"></a><strong>2.1 简单类型</strong><br> 
      <br> 
      固化在 Lysee 内核中的简单（基本）数据类型有以下 7 中:<br> 
      <br> 
      <table  border="0" align="center" cellpadding="4" cellspacing="0"> 
        <tr> 
          <th colspan="2" class="bottom_line">类型</th> 
          <th class="bottom_line">说明</th> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">bool</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">布尔值</td> 
          <td align="left" class="bottom_left_line">用于条件判断，只有 <strong>true</strong>，<strong>false</strong> 两个值</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">char</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">字符</td> 
          <td align="left" class="bottom_left_line">单字节 ANSI 字符</td> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">float</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">浮点型</td> 
          <td align="left" class="bottom_left_line">64位双精度浮点数</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">int</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">整型</td> 
          <td align="left" class="bottom_left_line">64位整数</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">money</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">货币</td> 
          <td align="left" class="bottom_left_line">精确到小数点后4位的货币类型</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">string</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">字符串</td> 
          <td align="left" class="bottom_left_line">以‘\0’结尾的单字节 ANSI 字符序列</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">time</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">时间</td> 
          <td align="left" class="bottom_left_line">由年、月、日、时、分、秒、毫秒构成</td> 
        </tr> 
    </table></td> 
  </tr> 
  <tr> 
    <td><a name="func" id="func"></a><strong>2.2. 函数类型</strong><br> 
      <br> 
      Lysee 函数可以细分为函数、方法和闭包三种，是程序运行的基础构件，可以通过参数进行传递。      <br> 
      <br> 
      <table  border="0" align="center" cellpadding="4" cellspacing="0"> 
        <tr> 
          <th class="bottom_line">类型</th> 
          <th class="bottom_line">说明</th> 
        </tr> 
        <tr> 
          <td bgcolor="#FFDFFF" class="bottom_line">函数</td> 
          <td align="left" class="bottom_left_line">在模块中明确定义的全局函数</td> 
        </tr> 
        <tr> 
          <td bgcolor="#FFDFFF" class="bottom_line">方法（method）</td> 
          <td align="left" class="bottom_left_line">在类、对象和接口中明确定义的函数</td> 
        </tr> 
        <tr> 
          <td bgcolor="#FFDFFF" class="bottom_line">闭包（closure）</td> 
          <td align="left" class="bottom_left_line">运行时刻生成并将其它函数的运行时状态打包到自身内部的函数</td> 
        </tr> 
    </table>    </td>
  </tr> 
  <tr> 
    <td><a name="class" id="class"></a><strong>2.3. 类</strong><br> 
      <br> 
    从 0.1.1.314 版本开始，Lysee 取消了 class 关键字，用户无法定义新类型，只能使用内核预定义类或二进制模块中的类。</td> 
  </tr> 
  <tr> 
    <td><a name="variant" id="variant"></a><strong>2.4. 变体类型</strong><br> 
      <br> 
      变体类型（variant）可以存储任意类型的数据，一个变体数据的实际类型由其运行时刻存储的具体内容决定。<br> 
      <br> 
      <table width="0%"  border="0" cellpadding="0" cellspacing="0" class="console"> 
        <tr> 
          <td nowrap class="dosprompt">&gt;&gt;&gt; v&nbsp;=&nbsp;&quot;string&quot;; <span class="comment">// a string</span><br> 
&gt;&gt;&gt;&nbsp;v&nbsp;=&nbsp;18; <span class="comment">// change to integer </span><br> 
&gt;&gt;&gt;&nbsp;v&nbsp;=&nbsp;strlist(); <span class="comment">// change to strlist</span> <br> 
&gt;&gt;&gt;&nbsp;v.add(&quot;hello&nbsp;world&quot;); <span class="comment">// add a line to strlist</span> <br> 
&gt;&gt;&gt;&nbsp;=&nbsp;v; <span class="comment">// print strlist content</span> <br> 
            hello&nbsp;world<br> 
&gt;&gt;&gt;</td> 
        </tr> 
    </table></td> 
  </tr> 
  <tr> 
    <td><a name="void" id="void"></a><strong>2.5. 无类型</strong><br> 
      <br> 
      无类型（<strong>void</strong>）用于定义返回值无意义的函数，不允许用 <strong>void</strong> 类型定义变量，它的值只有一个 <strong>nil</strong>。<br> 
      <br> 
      将 <strong>nil</strong> 赋值给其它类型的变量时，变量自动得到自己所属类型的缺省值：<br>      <br> 
      <table  border="0" align="center" cellpadding="4" cellspacing="0"> 
        <tr> 
          <th colspan="2" class="bottom_line">类型</th> 
          <th class="bottom_line">缺省值</th> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">bool</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">布尔值</td> 
          <td align="left" class="bottom_left_line">false</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">char</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">字符</td> 
          <td align="left" class="bottom_left_line">'\0'</td> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">float</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">浮点型</td> 
          <td align="left" class="bottom_left_line">0</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">int</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">整型</td> 
          <td align="left" class="bottom_left_line">0</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">money</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">货币</td> 
          <td align="left" class="bottom_left_line">0</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">string</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">字符串</td> 
          <td align="left" class="bottom_left_line">&quot;&quot;</td> 
        </tr> 
        <tr> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line"><strong class="lsp_code">time</strong></td> 
          <td align="left" bgcolor="#FFDFFF" class="bottom_line">时间</td> 
          <td align="left" class="bottom_left_line">0</td> 
        </tr>
      </table> 
      <br> 
      代码中可以用 <strong>nil</strong> 检测变量是否是缺省值：<br> 
      <br> 
      <table width="0%"  border="0" cellpadding="0" cellspacing="0" class="console"> 
        <tr> 
          <td width="400" nowrap class="dosprompt">&gt;&gt;&gt;&nbsp;strlist&nbsp;list;<br> 
&gt;&gt;&gt;&nbsp;=&nbsp;&quot;list has no value&quot; if&nbsp;(list&nbsp;==&nbsp;<span class="lsp_code">nil</span>);<br> 
            list has no value<br> 
&gt;&gt;&gt;&nbsp;= (10&nbsp;==&nbsp;<span class="lsp_code">nil</span>) ? 10 : 0;<br> 
            0 <br> 
&gt;&gt;&gt;</td> 
        </tr> 
    </table></td> 
  </tr> 
  <tr> 
    <td align="right" class="footer_line"><a href="301.html">&lt;PREV</a>&nbsp;&nbsp;<a href="index.html">HOME</a>&nbsp;&nbsp;<a href="303.html">NEXT&gt;</a></td> 
  </tr> 
</table> 
</body>
</html>
